﻿using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace DTcms.Web.Mvc.UI
{
    /// <summary>
    /// 会员登录过滤器
    /// </summary>
    public class UserValidateAttribute : ActionFilterAttribute
    {
        //是否验证登录
        public bool IsLogin { get; set; }

        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (!IsLogin) { return; }
            bool isLogin = new BaseController().IsUserLogin();
            if (!isLogin)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, new { status = 0, msg = "用户尚未登录或已超时！" }, "application/json");
            }
            base.OnActionExecuting(actionContext);
        }
    }
}